﻿<script type="text/javascript">
    //树
    var zNodes_Permission_Module_MoveNode = [];

    var zTree1_Permission_Module_MoveNode;
    var setting_Permission_Module_MoveNode;

    setting_Permission_Module_MoveNode = {
        checkable: false,
        async: true,
        isSimpleData: true,
        asyncUrl: "/Permission/Module/GetModuleMenus",  //获取节点数据的URL地址
        //asyncDataFilter: ajaxDataFilter,
        nameCol: "FullName",
        open: false,
        treeNodeKey: "Id",
        treeNodeParentKey: "ParentId",
        callback: {
            //             beforeAsync: zTreeBeforeAsync,
            asyncSuccess: zTreeOnAsyncSuccess_Permission_Module_MoveNode,
            //             asyncError: zTreeOnAsyncError,
            click: zTreeOnClick_Permission_Module_MoveNode
        }
    };

    function zTreeOnAsyncSuccess_Permission_Module_MoveNode(event, treeId, treeNode, msg) {
        //异步成功
    }
    var selectNodeId;
    //树的单击事件
    function zTreeOnClick_Permission_Module_MoveNode(event, treeId, treeNode) {
        //alert(treeNode.Id);
        $("#moduleID_Permission_Module_MoveNode").val(treeNode.Id);
        selectNodeId = treeNode.Id;
    }

    $(document).ready(function () {
        refreshTree_Permission_Module_MoveNode("/Permission/Module/GetModuleMenus");

    });
    function refreshTree_Permission_Module_MoveNode(asyncUrl) {
        $("#getUrl").html("");
        $("#onAsyncSuccessNode").html("<br/>");
        $("#onAsyncErrorNode").html("<br/>");
        setting_Permission_Module_MoveNode.asyncUrl = asyncUrl;
        if ((typeof asyncUrl) == "function") {
            $("#asyncUrlCode").html("setAsyncUrl");
        } else {
            $("#asyncUrlCode").html("\"" + asyncUrl + "\"");
        }
        zTree1_Permission_Module_MoveNode = $("#tree_Permission_Module_MoveNode").zTree(setting_Permission_Module_MoveNode, zNodes_Permission_Module_MoveNode);
    }
    $("#btnSave_Permission_Module_MoveNode").click(function () {

        $.post("/Permission/Module/Move", { "Id": "@ViewBag.Id", "pid": selectNodeId }, function (json) {
            DWZ.ajaxDone(json);
            if (json.statusCode == DWZ.statusCode.ok) {
                var selectedNode = zTree_permission_module_index.getSelectedNode();
                if (selectedNode.ParentId == json.data.ParentID) {//更新当前选中的节点
                    selectedNode.FullName = json.data.FullName;
                    zTree_permission_module_index.updateNode(selectedNode, true);
                } else {//将当前节点的父节点上移除，找到改变后的父节点并将当前新节点追加到该父节点上
                    zTree_permission_module_index.removeNode(selectedNode, true);
                    var newParentNode = zTree_permission_module_index.getNodeByParam("Id", json.data.ParentId);
                    zTree_permission_module_index.addNodes(newParentNode, json.data);
                }
                $("#rightDetail").load("/Permission/Module/Details/" + json.data.Id);
            }
            $.pdialog.closeCurrent();
        }, "json");
    });
    //    $("#btnCancel_Permission_Module_MoveNode").click(function () {
    //        $.pdialog.closeCurrent();
    //    });
</script>
<div class="pageContentD">
    <div class="pageFormContent" layouth="60">
        <ul id="tree_Permission_Module_MoveNode" class="ztree">
        </ul>
    </div>
    <div class='formBar'>
        @Html.Hidden("moduleID_Permission_Module_MoveNode", "0")
        <ul>
            <li>
                <button type="button" class="btn btn-success btn-sm" id="btnSave_Permission_Module_MoveNode">
                    保存</button>
            </li>
            <li>
                <button type="button" class="close btn btn-default btn-sm" id="btnCancel_Permission_Module_MoveNode">
                    取消</button>
            </li>
        </ul>
    </div>
</div>
